package solved;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;

/*
ID:		liluyan1
LANG:	JAVA
TASK:	concom
*/
public class concom {
	public static void main(String[] args) throws IOException {
		BufferedReader f = new BufferedReader(new FileReader("concom.in"));
		PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(
				"concom.out")));
		new concom().solve(f, out);
		out.close();
		System.exit(0);
	}
	
	private int N;
	private int[][] g;
	
	private void solve(BufferedReader f, PrintWriter out) throws IOException {
		g = new int[101][101];
		int n = read(f);
		N = 0;
		for (int i=0; i<n; i++) {
			int[] a = read(f, 3);
			g[a[0]][a[1]] = a[2];
			N = Math.max(N, Math.max(a[0], a[1]));
		}
		
		boolean[] visited = new boolean[N+1];
		
		ArrayDeque<Integer> queue = new ArrayDeque<Integer>();
		int[] sum = new int[N+1];
		ArrayList<Integer> owned = new ArrayList<Integer>();
		for (int i=1; i<=N; i++) {
			for (int j=1; j<=N; j++) {
				visited[j] = false;
				sum[j] = 0;
			}
			owned.clear();
			
			queue.add(i);
			visited[i] = true;
			
			while(!queue.isEmpty()) {
				int next = queue.remove();
				for (int j=1; j<=N; j++) {
					if (visited[j] || g[next][j]==0) continue;
					
					if (g[next][j] < 50) {
						sum[j] += g[next][j];
					}
					
					if (g[next][j] >=50 || sum[j] >= 50) {
						owned.add(j);
						visited[j] = true;
						queue.add(j);
					}
				}
			}
			
			Collections.sort(owned);
			for (int j : owned) {
				out.println(i + " " + j);
			}
		}
	}
	
	public int read(BufferedReader f) throws IOException {
		return Integer.parseInt(f.readLine());
	}
	
	public int[] read(BufferedReader f, int N) throws IOException {
		String[] t = f.readLine().split(" ");
		int[] a = new int[N];
		for (int i=0; i<N; i++) {
			a[i] = Integer.parseInt(t[i]);
		}
		return a;
	}
}
